package com.cnblsp2.android.study.androidresources.clip;

import java.util.Timer;
import java.util.TimerTask;

import com.cnblsp2.android.study.androidresources.R;

import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

public class ClipDrawableActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_clip);

		ImageView imageView = (ImageView) this.findViewById(R.id.activity_clip_image);

		final ClipDrawable drawable = (ClipDrawable) imageView.getDrawable();

		final Handler handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {

				if (msg.what == 0x1233) {
					// 修改ClipDrawable的level值
					drawable.setLevel(drawable.getLevel() + 200);
				}
			}
		};
		
		
		final Timer timer = new Timer();
		timer.schedule(new TimerTask() {

			@Override
			public void run() {
				Message msg = new Message();
				msg.what = 0x1233;
				//发送消息，通知应用修改ClipDrawable 对象的level值
				handler.sendMessage(msg);
				if(drawable.getLevel() >= 10000){
					timer.cancel();
				}
				
			}
		}, 0, 300);

	}

}
